home *** CD-ROM | disk | FTP | other *** search
/ Libris Britannia 4 / science library(b).zip / science library(b) / INFO / DOSTIPS5.ZIP / DOSBATCH next >
Text File  |  1986-12-17  |  62KB  |  1,684 lines

  1.                           Mass Deletes
  2.         (PC Magazine Vol 5 No 13 July 1986 User-to-User)
  3.  
  4.      It's easy to mass-erase unwanted files by using the ERASE command
  5. with ? and * wildcard characters.  This works file if the multiple
  6. files have some common elements to their names or extensions, but to
  7. erase multiple files without common portions of the names you normally
  8. have to issue the ERASE command once for each file you want to get rid
  9. of.  To get around this problem, and to make it easier to erase several
  10. files with one command, use this WIPEOUT.BAT file:
  11.  
  12. ECHO OFF
  13. :LOOP
  14. IF !%1 == ! GOTO ALLDONE
  15. IF EXIST %1 GOTO OKFILE
  16. ECHO File %1 not found ....
  17. GOTO GOON
  18. :OKFILE
  19. ERASE %1
  20. :GOON
  21. SHIFT
  22. GOTO LOOP
  23. :ALLDONE
  24.  
  25. To use WIPEOUT.BAT, type the files you want to erase after the WIPEOUT,
  26. with spaces between them.  For instance:
  27.  
  28. WIPEOUT c.doc c.wks d.doc
  29.  
  30. would remove c.doc, c.wks, and d.doc from your disk with a single
  31. command.  The batch file checks to see whether the files you specified
  32. are on your disk, tells you if they're not, and erases them if they
  33. are.  It uses SHIFT to juggle the specified filenames into the single
  34. %1 replaceable parameter, and an IF !%1 == ! test to see if it's
  35. finished.
  36.  
  37. -----------------------------------------------------------------
  38.                             ECHO OFF
  39.        (PC World July 1986 & November 1986 Star-Dot-Star)
  40.  
  41.      The default setting of ECHO ON for batch file commands can be
  42. quite annoying.  The obvious solution is to include an ECHO OFF command
  43. at the beginning of every batch file.  This has the equally annoying
  44. effect of displaying the ECHO OFF command whenever the batch file
  45. executes.  The ultimate solution is to patch COMMAND.COM to make ECHO
  46. OFF the default.
  47.      For DOS 3.1, simply change the appropriate byte from 1 to 0.
  48. To do so, use a copy of COMMAND.COM and proceed as follows:
  49.  
  50. A>debug command.com
  51. -e 1967 00
  52. -w
  53. Writing xxxx bytes
  54. -q
  55.  
  56.      For DOS 2.1, patch COMMAND.COM as follows:
  57.  
  58. A>debug command.com
  59. -e 096e 00
  60. -e 1734 3c 1f
  61. -e 366e 0d 0a 24
  62. -e 3672 26 c6 06 6e
  63. -e 3676 09 00 e9 05 e8
  64. -w
  65. Writing 4580 bytes
  66. -q
  67.  
  68.  
  69. -----------------------------------------------------------------
  70.                      Pause, S'il Vous Plait
  71.              (PC Magazine August 1986 User-to-User)
  72.  
  73.      If you distribute disks with batch files on them to non-English
  74. speaking users, the message "Strike a key when ready ..." generated by
  75. the PAUSE command may be meaningless.  To remedy this, substitute your
  76. own message by using ECHO and get rid of the normal English message by
  77. redirecting PAUSE to NUL.  This feature works only in DOS 3.0 or later.
  78. A French version would look like this:
  79.  
  80. ECHO OFF
  81. ECHO Presser une touche pour continuer
  82. PAUSE >NUL
  83.  
  84. Redirecting messages to NUL is a useful technique that can also prevent
  85. general batch file screen clutter.  Users have learned to start their
  86. systems by creating a RAMdisk and copying their most frequently used
  87. files to it.  Even with ECHO OFF, the results is a string of "1 File(s)
  88. copied" messages.  To keep the screen clean, add a ">NUL" to the end of
  89. each COPY instruction.
  90.  
  91. -----------------------------------------------------------------
  92.                   Putting DOS Variables to Work
  93.               (PC World August 1986 Star-Dot-Star)
  94.  
  95.      Buried within the DOS manual is a discussion of a feature that
  96. enables you to create variables for use within batch files.  This
  97. powerful feature makes creating sophisticated batch files a cinch.
  98. The technique works because DOS treats the percent sign (%) as a
  99. special mark that identifies replaceable parameters.  When you place
  100. percent signs on both sides of a name, DOS looks to an area of memory
  101. called the environment to find the value that replaces the variable
  102. name.  You can put values in the environment with the SET command.
  103.      Suppose you need to use a command frequently within a batch file.
  104. You could use the SET command to store that command in the environment
  105. under a short name (such as Z), and then use the variable %Z% within
  106. the batch file in lieu of the command itself.  SKIPLINE.BAT illustrates
  107. such a situation.
  108.      Values remain in the environment until you remove them or restart
  109. the computer.  Because of this, DOS variables can be enlisted to pass
  110. values between batch files.  One batch file can set a value in the
  111. environment; subsequent batch files can test that value using the IF
  112. subcommand, or they can use the value directly as demonstrated in
  113. SKIPLINE.BAT.
  114.      Editor's Note:  DOS reserves 127 bytes for environment space and
  115. expands that amount automatically unless you've loaded memory-resident
  116. software such as GRAPHICS.COM or SideKick.  If you run out of
  117. environment space (which will be indicated by a DOS error message),
  118. use the technique outlined in "For Environmentalists" in PC World
  119. April 1986 Star-Dot-Star.  (This article is contained in the previous
  120. tips file, DOSTIPS4.ARC.  -drw-)
  121.  
  122. -----------------------------------------------------------------
  123.                         Tax-Free Solution
  124.               (PC World August 1986 Star-Dot-Star)
  125.  
  126.      According to IRS regulations, anyone who uses a computer for both
  127. personal and business purposes must keep contemporaneous records to
  128. document deductible expenses.  You can buy any of several utility
  129. programs that monitor PC usage, but you can also accomplish the task
  130. with the batch file USELOG.BAT.
  131.      USELOG.BAT relies heavily on DOS redirection capabilities.  It
  132. requires that you first create a file called CR.DAT and keep it on
  133. disk so DATE and TIME commands can be redirected.  To create CR.DAT,
  134. type: COPY CON:CR.DAT <Enter>, press <Enter> again, and then <Ctrl>-Z
  135. and <Enter>.  Be careful when creating USELOG.BAT; the presence and
  136. placement of many characters are critical.  This is especially true
  137. for the greater-than and less-than symbols; if you omit one where two
  138. are required, the contents of the master file may be erased each time
  139. USELOG.BAT is run.
  140.      You can invoke the program in two ways: type USELOG followed by
  141. up to nine words that describe the purpose of the computer session.
  142. (Do not use the greater-than or less-than symbols in your description.)
  143. Or simply type USELOG and await prompting for a description.  If you
  144. opt for the latter method, you must remember to press <Ctrl>-Z followed
  145. by <Enter> to mark the end of the description.
  146.      When it is run, USELOG.BAT appends the date, time, and session
  147. information to the master file USELOG.DAT.  The program performs with
  148. acceptable speed on a floppy-based system and executes in a flash when
  149. run on a hard disk.  If you have a RAM disk, you may want to modify
  150. USELOG.BAT to operate on RAM-based files, then copy the master file
  151. onto a hard or floppy disk.  Once the program is working, you can
  152. easily document all your computer activity -- including changing tasks
  153. after starting your PC.
  154.  
  155. echo off
  156. cls
  157. rem Note: Requires file CR.DAT containing 1 blank line
  158. date<cr.dat>>uselog.dat
  159. time<cr.dat>>uselog.dat
  160. cls
  161. echo Purpose: >>uselog.dat
  162. if X==%1X goto cont
  163. echo Updating usage log...
  164. echo %1 %2 %3 %4 %5 %6 %7 %8 %9 >>uselog.dat
  165. goto end
  166. :cont
  167. echo Describe the purpose of this computer session,
  168. echo then press Ctrl-Z and then press ENTER:
  169. copy use log.dat+con uselog.dat/b >nul
  170. :end
  171.  
  172. -----------------------------------------------------------------
  173.                    Fast IBM Batch File Editor
  174.        (COMPUTE! Magazine September 1986 by Tony Roberts)
  175.  
  176.      The power of the batch file quickly becomes evident to anyone who
  177. works regularly in DOS.  The AUTOEXEC.BAT handles a variety of chores
  178. each time the system is booted, and any number of other BAT files stand
  179. by, ready to help with such tasks as initializing applications, sending
  180. out printer codes, and presenting program menus.
  181.      The problem with batch files is that to be effective and helpful,
  182. they need to be adjusted as your system grows and your applications
  183. change.  Performing the necessary batch-file maintenance, however, is
  184. often so cumbersome that it's discouraging.  Loading a full-blown word
  185. processor or even using EDLIN to edit a five- to ten-line batch file
  186. can be a lot more time and trouble than it's worth.
  187.      EDBAT.COM is a full-screen editor with very limited features.
  188. Because it is designed for speed, it limits itself to files of fewer
  189. than 512 bytes -- adequate for most batch files.  When called, the
  190. program clears the screen and displays the file you want to edit.
  191. Using the cursor keys, you can move to the appropriate place, make the
  192. necessary changes, and press Alt-S to save the edited file.  It is not
  193. impossible to open a file, edit it, close it, and be back at the DOS
  194. prompt in as little as 15 seconds.
  195.      The price you pay for this fast operation is that EDBAT has very
  196. few features.  You're essentially limited to the regular character keys
  197. and the cursor keys.  The Insert key does not work, the Delete key does
  198. not work, nor do the function keys perform any function.  The Backspace
  199. key moves the cursor back a character, but it does not perform a delete.
  200. For batch file editing, none of these is particularly restrictive.
  201. You're usually just performing one or two simple operations such as
  202. adding, deleting, or correcting a line.  EDBAT can handle all these
  203. tasks efficiently.
  204.      EDBAT.COM is created from the EDBAT.BAS listing below.  To run
  205. EDBAT.COM, enter this line at the DOS prompt:
  206.  
  207. EDBAT filename
  208.  
  209. EDBAT.COM must be on the disk in the current drive when you enter this
  210. command.  Filename is the name of the file you wish to edit.  Full
  211. drive and subdirectory specifications are allowed when indicating a
  212. filename.  If the file is too long or if EDBAT is unable to open the
  213. file, the program will print a message and exit.  If the file you have
  214. specified does not exist, EDBAT assumes you are creating a new file.
  215.      The file you are to edit is displayed on the screen below a line
  216. containing the program title and the name of the current file.  If you
  217. have started a new file, the screen's work area will be blank.
  218.      Use the cursor keys to move around the file, editing as needed.
  219. Notice that a triangle signals the end of each line.  If you decide to
  220. cut a line short, move to the appropriate spot and press Enter.  A
  221. trianble is inserted and the cursor moves to the beginning of the next
  222. line.  The screen may continue to show characters beyond the end-of-
  223. line marker, but they will be ignored when the file is saved.
  224.      To delete an entire line, simply move to the first position on
  225. that line and press Enter.  An end-of-line marker appears at that
  226. spot, indicating that the line will be ignored.
  227.      Inserting a line is slightly more difficult since there is no
  228. insert function.  Move the cursor to the end-of-line marker on the
  229. line that will precede your new line.  Press Ctrl-Y and a down-arrow
  230. character will replace the end-of-line marker.  Add the new line right
  231. after the down arrow and press Enter as usual.  When the file is saved,
  232. the lines will be adjusted.
  233.      When you're finished editing, press Alt-S to save the file.  The
  234. program's save routine reads the screen and saves what it sees to your
  235. file.  It begins with the first line of the text area and continues
  236. until it finds a space in the first position of any line.  EDBAT
  237. ignores any characters in a line which follow the first end-of-line
  238. marker.
  239.      The only other option the program offers is Alt-Q, the Quit
  240. option, which returns you to DOS without changing the original file.
  241. In nearly every case, your entire file will fit easily on the screen.
  242. If part of your file scrolls off the screen, use Alt-Q to quit and
  243. find another method of editing the file.  EDBAT cannot save what it
  244. cannot see.
  245.      EDBAT does not make a backup copy of your original file.  In most
  246. cases, though, a backup copy of a very short file is superfluous.
  247.  
  248. EDBAT.COM Command Summary:
  249.  
  250. Alt-Q    Quit
  251. Alt-S    Save
  252. Ctrl-Y    Multistatement delimiter (prints as a down arrow)
  253. Enter    End-of-line (prints as left-pointing triangle)
  254. Space    Space in first position of line signals text end
  255.  
  256.  
  257. EDBAT.BAS:
  258.  
  259. 10 CLS
  260. 20 OPEN "EDBAT.COM" AS 1 LEN=1
  261. 30 FIELD 1,1 AS A$
  262. 40 PRINT:PRINT"Writing EDBAT.COM to disk....."
  263. 50 FOR I=1 TO 8:READ B$:GOSUB 130:NEXT I
  264. 60 FOR I=1 TO 75:B$="5F":GOSUB 130:NEXT I
  265. 70 B$="24":GOSUB 130
  266. 80 FOR I=1 TO 74:B$="0":GOSUB 130:NEXT I
  267. 90 FOR I=1 TO 648:READ B$:GOSUB 130:NEXT I
  268. 100 CLOSE
  269. 110 PRINT:PRINT"EDBAT.COM has been created."
  270. 120 END
  271. 130 'Write byte to disk
  272. 140 LSET A$=CHR$(VAL("&H"+B$))
  273. 150 PUT #1
  274. 160 RETURN
  275. 170 DATA E9,E0,0,45,64,42,61,74,2,0
  276. 180 DATA 2,50,6C,65,61,73,65,20,73,70,65,63,69,66,79,20
  277. 190 DATA 66,69,6C,65,6E,61,6D,65,2E,D,A,24,45,72,72,6F
  278. 200 DATA 72,20,6F,70,65,6E,69,6E,67,20,66,69,6C,65,2E,D
  279. 210 DATA A,24,46,69,6C,65,20,74,6F,6F,20,6C,6F,6E,67,2E
  280. 220 DATA D,A,24,FC,BF,54,1,BE,80,0,AC,A2,99,1,FE,E
  281. 230 DATA 99,1,3C,0,75,9,BA,A1,1,E8,7,2,E8,25,2,AC
  282. 240 DATA 3C,D,74,3,AA,EB,F8,E8,BA,1,73,E,3D,2,0,74
  283. 250 DATA 30,BA,BC,1,E8,EC,1,E8,A,2,BA,26,4,8B,1E,9A
  284. 260 DATA 1,8B,E,9F,1,B4,3F,CD,21,3B,6,9F,1,75,C,E8
  285. 270 DATA A0,1,BA,D2,1,E8,CB,1,E8,E9,1,A3,96,1,E8,91
  286. 280 DATA 1,E8,CB,1,BA,3,1,E8,B9,1,C6,6,9E,1,0,C6
  287. 290 DATA 6,9D,1,14,E8,60,1,BE,55,1,33,C9,8A,E,99,1
  288. 300 DATA AC,8A,D0,80,FA,61,72,3,80,E2,DF,E8,9C,1,E2,F0
  289. 310 DATA C6,6,9E,1,2,C6,6,9D,1,0,E8,3A,1,83,3E,96
  290. 320 DATA 1,0,74,1F,FC,BE,26,4,8B,E,96,1,AC,8A,D0,80
  291. 330 DATA FA,D,75,7,B2,11,E8,71,1,B2,D,E8,6C,1,E2,EC
  292. 340 DATA E8,14,1,B4,0,CD,16,3C,0,74,13,3C,D,74,A,3C
  293. 350 DATA 8,B4,4B,74,1C,3C,19,72,EA,E8,1F,1,EB,E5,80,FC
  294. 360 DATA 48,75,E,80,3E,9E,1,2,74,D9,FE,E,9E,1,E8,E6
  295. 370 DATA 0,80,FC,4B,75,E,80,3E,9D,1,0,74,C6,FE,E,9D
  296. 380 DATA 1,E8,D3,0,80,FC,4D,75,E,80,3E,9D,1,4F,74,B3
  297. 390 DATA FE,6,9D,1,E8,C0,0,80,FC,50,75,E,80,3E,9E,1
  298. 400 DATA 18,74,A0,FE,6,9E,1,E8,AD,0,80,FC,10,75,6,E8
  299. 410 DATA FD,0,E8,F,1,80,FC,1F,75,89,C7,6,96,1,0,0
  300. 420 DATA BF,26,4,C6,6,9E,1,2,C6,6,9D,1,0,E8,87,0
  301. 430 DATA C6,6,95,1,0,B4,8,CD,10,3C,20,74,4E,3C,11,75
  302. 440 DATA 9,FE,6,9E,1,E8,6F,0,EB,DE,80,3E,95,1,50,77
  303. 450 DATA 18,B4,8,CD,10,3C,11,74,10,3C,19,75,1C,B0,D,AA
  304. 460 DATA FF,6,96,1,B0,A,EB,11,90,B0,D,B4,A,AB,83,6
  305. 470 DATA 96,1,2,FE,6,9E,1,EB,AF,AA,FF,6,96,1,FE,6
  306. 480 DATA 95,1,FE,6,9D,1,E8,2E,0,EB,BF,F8,BA,55,1,B4
  307. 490 DATA 3C,B9,0,0,CD,21,73,9,BA,BC,1,E8,65,0,E8,83
  308. 500 DATA 0,8B,D8,8B,E,96,1,BA,26,4,B4,40,CD,21,E8,21
  309. 510 DATA 0,E8,5B,0,E8,6D,0,8A,36,9E,1,8A,16,9D,1,B4
  310. 520 DATA 2,CD,10,C3,F8,BA,55,1,B0,2,B4,3D,CD,21,A3,9A
  311. 530 DATA 1,C3,8B,1E,9A,1,B4,3E,CD,21,C3,8A,D0,80,FA,D
  312. 540 DATA 74,8,E8,25,0,FE,6,9D,1,C3,B2,11,E8,1B,0,B2
  313. 550 DATA D,E8,16,0,B2,A,E8,11,0,FE,6,9E,1,C6,6,9D
  314. 560 DATA 1,0,C3,50,B4,9,CD,21,58,C3,B4,2,CD,21,C3,B4
  315. 570 DATA F,CD,10,88,3E,9C,1,B4,0,B0,2,CD,10,B4,5,B0
  316. 580 DATA 0,CD,10,C3,CD,20
  317.  
  318. -----------------------------------------------------------------
  319.                         Best Batch Branch
  320.        (PC Magazine Vol 5 No 8 Apr 29, 1986 User-to-User)
  321.  
  322.      Long batch files containing numerous "if ... goto" conditional
  323. statements tend to slow down dramatically as processing moves further
  324. along.  DOS searches slowly for each new label from the top of the
  325. file, yielding a pathetic 5- to 10-second delay, even on an AT, if
  326. the label occurs near the end of a long batch.  There is a way to get
  327. rid of all the labels and "if errorlevel ... goto" statements, allowing
  328. a batch file to work at top speed and still contain numerous
  329. conditional branches.
  330.      Most batches can be controlled with a simple Y(es) or other
  331. single-key response to each request.  The GETKEY technique described
  332. in an earlier User-to-User sets a different errorlevel for every
  333. response.  Because DOS returns a "true" if errorlevel <= the set
  334. value, batch files ordinarily require four "if errorlevel" tests to
  335. obtain "true" on Y or y but "false" on other keys.
  336.      GETYES.COM performs these tests, thereby removing them from the
  337. batch.  It sets errorlevel 255 for Y or y and errorlevel 0 for any
  338. other key.  This lets you directly perform an operation with the
  339. statement "if errorlevel 255 (perform some DOS function)".  GETYES.COM
  340. is created with GETYES.BAS below.
  341.      You can next "if" conditionals on one line of a batch file for
  342. further flexibility and control; for example, "if errorlevel 255 if
  343. exist filename (perform some DOS function)" or "if errorlevel 255 if
  344. x == %1 (perform some DOS function)".  This doesn't seem to be
  345. documented in the DOS manual.
  346.  
  347. 100 'GETYES.BAS
  348. 110 OPEN "GETYES.COM" AS #1 LEN=1
  349. 120 FIELD #1,1 AS D$
  350. 130 FOR B=1 TO 18
  351. 140 READ A$:LSET D$=CHR$(VAL("&H"+A$))
  352. 150 PUT #1:NEXT:CLOSE
  353. 160 DATA B4,00,CD,16,3C,59,74,04,3C
  354. 170 DATA 79,75,02,B0,FF,B4,4C,CD,21
  355.  
  356.      Editor's Note:  This technique makes batch branching a pleasure.
  357. If you want to use N and n rather than Y and y to trigger errorlevel,
  358. substitute 4E for 59 in line 160 and 6E for 79 in line 170, and change
  359. the reference from GETYES.COM to GETNO.COM.  To test this after
  360. creating the GETYES.COM program, use this TESTTHIS.BAT file:
  361.  
  362.  
  363.  
  364. echo off
  365. :start
  366. echo Hit y or Y or another key
  367. getyes
  368. if errorlevel 255 goto :yes
  369. goto :no
  370. :yet
  371. echo ...you said yes
  372. goto :continue
  373. :no
  374. echo ...you didn't hit y or Y
  375. :continue
  376. echo Now, want to quit (y/n)?
  377. getyes
  378. if errorlevel 255 goto :exit
  379. goto :start
  380. :exit
  381.  
  382.      The nesting abilities allow even more power.  To test these,
  383. revise the fifth line of TESTTHIS.BAT to read:
  384.  
  385. if errorlevel 255 if Z==%1 goto :yes
  386.  
  387. Then, if you execute TESTTHIS.BAT again, hitting Y or y at the first
  388. prompt will not result in a branch as it did earlier.  To make both
  389. of the nested conditions true, instead of executing the batch file by
  390. typing TESTTHIS, at the DOS prompt type:
  391.  
  392. TESTTHIS Z
  393.  
  394. and hit Y or y when asked.  The Z after the filename will replace the
  395. %1 parameter, and since both conditions (the errorlevel and the Z==Z)
  396. are true, the batch file will work as advertised.  If you try this, be
  397. sure to type in a capital Z; DOS, which much of the time converts
  398. lowercase keyboard inputs into uppercase ones, is case-sensitive here.
  399.  
  400.                            Case Closed
  401.       (PC Magazine Vol 5 No 16 Sept 30, 1986 User-to-User)
  402.  
  403.      The GETYES.COM batch branch technique relies on Y or N responses
  404. and works only if the number of choices is small.  A better method for
  405. branching is to adapt the GETKEY.COM program on which GETYES is based.
  406.      GETKEY reports different IF ERRORLEVEL values for upper- and
  407. lowercase letters.  It's smarter to add a line in GETKEY that will
  408. convert all lowercase letters to uppercase.  To do this, use an ASCII
  409. word processor or DOS's COPY.COM to create a script called GETFIX,
  410. containing the lines:
  411.  
  412. N GETNEW.COM
  413. A
  414. MOV AH,0
  415. INT 16
  416. AND AL,DF
  417. MOV AH,4C
  418. INT 21
  419.  
  420. RCX
  421. A
  422. W
  423. Q
  424.  
  425. Then create the GETNEW.COM file by putting GETFIX on the same disk as
  426. DEBUG and typing:
  427.  
  428. DEBUG < GETFIX
  429.  
  430.      GETNEW.COM will let you work with just capital-letter values,
  431. reducing the IF ERRORLEVEL tests by half.  The example batch file
  432. below will let you type in either A, B, or C (or a, b, or c) and will
  433. then figure out with a minimum of tests which keys you hit.
  434.  
  435. ECHO OFF
  436. :MENU
  437. ECHO ------------------------------
  438. ECHO Hit A, B, or C (or a, b, or c)
  439. ECHO -- or hit Q (or q) to quit --
  440. ECHO ------------------------------
  441. GETNEW
  442. IF ERRORLEVEL 82 GOTO OOPS
  443. IF ERRORLEVEL 81 GOTO END
  444. IF ERRORLEVEL 68 GOTO OOPS
  445. IF ERRORLEVEL 67 GOTO C
  446. IF ERRORLEVEL 66 GOTO B
  447. IF ERRORLEVEL 65 GOTO A
  448. GOTO OOPS
  449. :C
  450. ECHO YOU HIT A C
  451. GOTO MENU
  452. :B
  453. ECHO YOU HIT A B
  454. GOTO MENU
  455. :A
  456. ECHO YOU HIT AN A
  457. GOTO MENU
  458. :OOPS
  459. ECHO WRONG ...
  460. GOTO MENU
  461. :END
  462.  
  463.      While reducing the number of IF ERRORLEVEL tests will speed up
  464. batch file execution, you can make your batch files run much faster
  465. by running them out of RAMdisks and arranging the test properly.
  466. Since batch files search for labels from the top of each batch file,
  467. put nonessential statements at the bottom (and GOTO them), and put the
  468. labels that users are most likely to choose nearest the top.
  469.      Finally, don't exit with an :END label at the end of the batch
  470. file, which is the most time-consuming search of all.  Instead,
  471. execute a dummy batch file.  Since DOS doesn't allow nesting of batch
  472. files, this will drop you to the DOS prompt.
  473.      Editor's Note:  ANDing any ASCII value with 223 (hex DF) will
  474. capitalize lowercase letters and leave uppercase letters alone.  The
  475. logical AND operation works by comparing two values (the example below
  476. compares 1 bit at a time) and returning a 1 only when both values are
  477. nonzero.
  478.  
  479. 1 AND 1 = 1
  480. 1 AND 0 = 0
  481. 0 AND 1 = 0
  482. 0 AND 0 = 0
  483.  
  484. 223 equals binary 11011111.  Capital A (decimal 65) is binary 01000001,
  485. while lowercase a (decimal 97) is binary 01100001.  The AND operation
  486. on these numbers could be represented as:
  487.  
  488.     01000001 (65)
  489. AND 11011111 (223)
  490.     --------
  491.     01000001 (65)
  492.  
  493.     01100001 (97)
  494. AND 11011111 (223)
  495.     --------
  496.     01000001 (65)
  497.  
  498. ANDing either a 0 or a 1 with 1 in effect leaves the value alone, and
  499. ANDing both a 0 and 1 with 0 in effect turns the value into a 0.  The
  500. binary number 11011111 forces the 2^5 bit -- the sixth one from the
  501. right -- to become a 0 and leaves all the other bits the way they were.
  502. (The rightmost bit is 2^0; the left most is 2^7.)
  503.      The only difference between a lowercase letter and its capital
  504. counterpart is that the 2^5 bit is "set" (=1) in the lowercase version.
  505. ANDing it with 11011111 "unsets" the bit, chaning it to a 0 and
  506. lowering the ASCII value by 32.
  507.      To reverse the process and turn capital letters into lowercase
  508. ones, use the logical OR operation to OR a value with 32.
  509.  
  510. 1 OR 1 = 1
  511. 1 OR 0 = 1
  512. 0 OR 1 = 1
  513. 0 OR 0 = 0
  514.  
  515. 32 equals binary 00100000.  Since ORing either a 1 or a 0 with 0 in
  516. effect leaves the value alone, and ORing either a 1 or a 0 with 1 in
  517. effect turns the value into a 1, the binary number 00100000 forces the
  518. 2^5 bit to become a 1 and leaves all the other bits the way they were.
  519.      This "sets" the unset 2^5 bit in an uppercase letter, changing it
  520. to a 1 and raising the ASCII value by 32.
  521.  
  522.    01000001 (65)
  523. OR 00100000 (32)
  524.    --------
  525.    01100001 (97)
  526.  
  527.    01100001 (97)
  528. OR 00100000 (32)
  529.    --------
  530.    01100001 (97)
  531.  
  532.      GETNEW.COM is a significant improvement over the previous
  533. GETKEY.COM routine.  Using GETNEW in your batch files will let you
  534. offer 26 choices -- amost certainly enough -- while keeping the number
  535. of IF ERRORLEVEL tests to a minimum.
  536.      Of the other batch file enhancement techniques suggested, by far
  537. teh most important is to run any branching batch file from a RAMdisk.
  538. the VDISK.SYS "virtual disk" comes free with DOS and is smart,
  539. flexible, and extremely easy to use.  You don't even have to change
  540. any system board DIP switch settings to take advantage of a RAMdisk's
  541. speed gain.
  542.      One more note -- DOS in fact does allow batch file nesting.  To
  543. do so, preface the name of the batch file to be nested with COMMAND /C,
  544. which runs it out of a secondary command processor.  (See "Nested FORs"
  545. PC Mag Vol 5 No 16 Sept 30, 1986 User-to-User below.)
  546.  
  547.  
  548.                          Batch Feedback
  549.        (PC Magazine Vol 5 No 21 Dec 9, 1986 User-to-User)
  550.  
  551.      The GETNEW.COM program provides a useful way to implement an
  552. interactive batch file in which a letter typed on the keyboard sets
  553. the ERRORLEVEL to its corresponding ASCII value.  However, the program
  554. does not echo the character typed.  Since batch files execute slowly,
  555. even on a hard disk system, an impatient user may repeatedly press the
  556. key until a response is seen.  These extra keystrokes are stored in the
  557. input buffer and may cause undesired effects once control is passed to
  558. a program.
  559.      A simple modification of GETNEW that provides feedback to the user
  560. by echoing the character typed is:
  561.  
  562. N GETNEW.COM
  563. A
  564. MOV AH,0
  565. INT 16
  566. OR AL,20
  567. MOV DL,AL
  568. MOV AH,02
  569. INT 21
  570. MOV AH,4C
  571. INT 21
  572.  
  573. RCX
  574. 10
  575. W
  576. Q
  577.  
  578. (Name this file GETNEW.SCR.  Then use DEBUG to create GETNEW.COM by
  579. typing:  DEBUG < GETNEW.SCR.)  Since most users leave CapsLock off and
  580. work with lowercase letters, the program is modified to convert all
  581. input to lowercase.  If uppercase conversion is preferred, replace the
  582.  
  583. OR AL,20
  584.  
  585. with
  586.  
  587. AND AL,DF
  588.  
  589.      The batch file below is a program that uses GETNEW to run any of
  590. a selection of programs listed on a menu.  To speed execution, the menu
  591. is stored in an ASCII file MENU.TXT (see below) in the root directory.
  592. This batch file can replace a number of smaller files used to call
  593. individual programs.  Since each batch file replaced uses 4,096
  594. characters of storage on a hard disk regardless of how small it is,
  595. the savings in disk storage space can be considerable.
  596.  
  597. echo off
  598. :restart
  599. cls
  600. prompt
  601. cd\
  602. path\
  603. type MENU.TXT
  604. getnew
  605. echo ...Wait...
  606. if errorlevel=114 goto errmsg
  607. if errorlevel=113 goto q
  608. if errorlevel=105 goto errmsg
  609. if errorlevel=104 goto h
  610. if errorlevel=103 goto g
  611.      .
  612.      .
  613.      .
  614. if errorlevel=97 goto a
  615. :errmsg
  616. echo Invalid response.
  617. goto restart
  618. :a
  619. echo Running [program a]...
  620. cd\[subdirectory a]
  621. [batch instructions to run program a]
  622.      .
  623.      .
  624.      .
  625. goto restart
  626. :b
  627. echo Running [program b]...
  628. cd\[subdirectory b]
  629. [batch instructions to run program b]
  630.      .
  631.      .
  632.      .
  633. goto restart
  634. :c
  635.    [etc.]
  636.      .
  637.      .
  638.      .
  639. :q
  640. cls
  641. prompt type HELP for menu$_$n$g
  642.  
  643.      Following is the ASCII file MENU.TXT which should be stored in the
  644. root directory.  The file ends after the : on the last line without a
  645. carriage return, so that the input letter to be echoed will appear on
  646. the same line as the request.
  647.  
  648.  type     to do this
  649. -------   ----------------
  650.    a      run [program a]
  651.    b      run [program b]
  652.    c      run [program c]
  653.                 .
  654.                 .
  655.                 .
  656.    h      run [program h]
  657.    q      exit this menu to DOS
  658.  
  659.  When in DOS, type HELP to get back to this menu
  660.  Type letter (a through h or q):
  661.  
  662. Editor's Note:  This modification can come in handy if you run your
  663. batch files off floppies or slow hard disks.  But it's far more
  664. efficient to create a small RAMdrive when you boot up (the DOS
  665. VDISK.SYS will handle the job), copy your important batch files to
  666. the RAMdrive, PATH to it, and execute everything out of memory.  The
  667. technique of using the TYPE MENU.TXT command rather than a string of
  668. ECHO statements to display a long menu is a good one, as is leaving
  669. the final carriage return off the last line of the .TXT file that
  670. acts as a prompt.  (Don't omit carriage returns from final ECHO
  671. commands, however, or DOS won't execute them properly.)  The 4K
  672. minimum file length applies just to XT hard disks under DOS 2.x; an
  673. AT running DOS 3.x gets away with files half that size.
  674.  
  675.  
  676. -----------------------------------------------------------------
  677.                            Nested FORs
  678.       (PC Magazine Vol 5 No 16 Sept 30, 1986 User-to-User)
  679.  
  680.      Trying to next FOR batch subcommands usually results in a "FOR
  681. cannot be nested" error message.  The solution is to load a COMMAND /C
  682. secondary command processor before the second FOR.  This technique will
  683. work more than the two levels deep in the example shown below.  If you
  684. try this technique in direct DOS mode (rather than in a batch file),
  685. use single % signs rather than the double % signs required for batch
  686. files.
  687.  
  688. for %%a in (1 2 3) do for %%b in (A B C) do echo %%a %%b
  689.  
  690. for %%a in (1 2 3) do command/c for %%b in (A B C) do echo %%a %%b
  691.  
  692.      Editor's Note:  DOS doesn't seem especially picky about what
  693. COMMAND /C syntax you use.  All of these variables work fine when
  694. inserted in the example shown above:
  695.  
  696. COMMAND /C FOR
  697. COMMAND/C FOR
  698. COMMAND /CFOR
  699. COMMAND/CFOR
  700.  
  701. -----------------------------------------------------------------
  702.                         Resounding ECHOs
  703.         (PC Magazine Vol 5 No 16 Sept 30, 1986 PC Tutor)
  704.  
  705.      Several readers pointed out that using ASCII 255 to get DOS 3.1
  706. to ECHO blank lines (PC Tutor Vol 5 No 10 May 27, 1986), an alternative
  707. solution (a patch to COMMAND.COM) had already appeared in User-to-User
  708. Vol 4 No 24 November 26, 1985.
  709.      The COMMAND.COM patch is not a good solution in this case.  The
  710. patch doesn't really solve the problem, since for every new DOS version
  711. somebody will have to figure out where to put similar new patches.
  712.      ECHO has been fixed in DOS 3.1, so patching COMMAND.COM to
  713. duplicate the effect of an old bug doesn't make sense.  ECHO should
  714. not act differently if it is followed by one blank space or by two
  715. blank spaces, as it does in DOS 2.0 through 3.0.  The real problem
  716. with ECHO is its insistence on issuing "Echo is on" and "Echo is off"
  717. messages.  If ECHO did not dish out these useless messages, it would
  718. simply echo a blank line when entered without a parameter.
  719.      In the case at hand, the person who asked about echoing blank
  720. lines was involved in maintaining batch files in a corporate setting
  721. where they are used on many different PCs.  Patching COMMAND.COM on
  722. each of these machines rather than changing the batch files (which
  723. require periodic redistribution anyway) didn't seem to be a reasonable
  724. approach.  The use of EDLIN, with its redirection of standard input,
  725. illustrated some valuable techniques that could be applied in other
  726. circumstances where changes must be made in several different files.
  727.      The recommendation to change the ECHO statements to echo an
  728. ASCII 255 (which displays as a blank) is not the only good fix,
  729. however.  Several readers pointed out that:
  730.  
  731. ECHO.
  732.  
  733. will print a blank lines, as will also
  734.  
  735. ECHO:
  736.  
  737. Both are cleaner and much easier to create with most text editors.
  738. Note that the period and colon must immediately follow ECHO.
  739.      You can also use a slash, backslash, double quote, left or right
  740. bracket, or a plus sign immediately following the word ECHO.  What all
  741. these characters have in common is that they may not be used in file
  742. or command names (thus they obviously aren't part of the command),
  743. they are not delimiters, and they serve no other purpose on a command
  744. line (as would the angle brackets, for instance).  All were tested
  745. with DOS 3.2 and they work.
  746.      Another reader suggested creating ASCII files containing the text
  747. to be displayed and using the batch file to TYPE these files to the
  748. screen after turning ECHO off.  This is most useful when creating
  749. full-screen displays from batch files, since you can put ANSI control
  750. sequences in the file for moving the cursor around and highlighting.
  751.  
  752. -----------------------------------------------------------------
  753.                       Batch String Comparer
  754.        (PC Magazine Vol 5 No 17 Oct 14, 1986 User-to-User)
  755.  
  756.      DOS makes it easy to control branching by passing parameters into
  757. batch files form the command line.  You can then use IF statements to
  758. compare such parameters and branch accordingly.  But DOS is case
  759. sensitive, which means that a string N characters long requires 2^N
  760. IF statements to compare all of the permutations of uppercase and
  761. lowercase letters.  A string containing the three characters ABC would
  762. require eight IF statements (testing for aBc, ABc, aBC, and so on) to
  763. exhaust every possible combination.  This increases execution time
  764. dramatically.
  765.      COMPARE.COM compares two strings and ignores the case of the
  766. alphabetic characters.  On return, it sets ERRORLEVEL 255 if both
  767. strings are equal and ERRORLEVEL 0 if they are not equal or if a
  768. syntax error has occurred.  After executing COMPARE.COM, your batch
  769. file may take appropriate action with the statement "IF ERRORLEVEL 255
  770. (do something)."
  771.      To test COMPARE.COM, run the sample COMPTEST.BAT batch file.  At
  772. the DOS prompt type:
  773.  
  774. COMPTEST hello HELLO
  775.  
  776. and it will respond with the message:
  777.  
  778. The strings are equal.
  779.  
  780.      IF ERRORLEVEL is a necessity in large batch files, and this lets
  781. you use words rather than single characters to trigger branching,
  782. making things far friendlier.
  783.  
  784. COMPTEST.BAT:
  785.  
  786. echo off
  787. if %2!==! goto oops
  788. compare %1==%2
  789. if errorlevel 255 goto match
  790. echo The strings are not equal.
  791. goto end
  792. :match
  793. echo The strings are equal.
  794. goto end
  795. :oops
  796. echo The format required is:
  797. echo COMPTEST STRING1 STRING2
  798. :end
  799.  
  800.  
  801. COMPARE.BAS:
  802.  
  803. 100 'COMPARE.BAS:  Creates COMPARE.COM.
  804. 110 PRINT "Checking DATA statements ...."
  805. 120 FOR B=1 TO 9:FOR C=1 TO 17:READ A$:IF C<17 THEN 140
  806. 130 Z#=Z#+VAL(A$)
  807. 140 NEXT:NEXT
  808. 150 IF Z#=13419 THEN RESTORE:GOTO 180
  809. 160 PRINT "Wrong number of DATA statements, or error in a big"
  810. 170 PRINT "number at the end of a line -- check and redo.":END
  811. 180 FOR B=1 TO 9:FOR C=1 TO 16:READ A$:TTL=TTL+VAL("&H"+A$)
  812. 190 NEXT
  813. 200 READ S:IF S=TTL THEN 220
  814. 210 PRINT "DATA error in line";B*10+260;" -- check and redo.":END
  815. 220 TTL=0:NEXT:RESTORE
  816. 230 OPEN "COMPARE.COM" AS #1 LEN=1:FIELD #1,1 AS D$
  817. 240 FOR B=1 TO 9:FOR C=1 TO 16:READ A$:LSET D$=CHR$(VAL("&H"+A$))
  818. 250 PUT #1:NEXT:READ DUMMY$:NEXT:CLOSE
  819. 260 PRINT "COMPARE.COM created."
  820. 270 DATA BE,81,00,FC,AC,3C,20,74,FB,3C,0D,74,4C,4E,56,5F,1726
  821. 280 DATA 2B,C9,AC,3C,3D,74,17,3C,20,74,0A,3C,0D,74,3A,E8,1373
  822. 290 DATA 44,00,41,EB,ED,AC,3C,20,74,FB,3C,3D,75,2B,AC,3C,1749
  823. 300 DATA 3D,75,26,AC,3C,20,74,FB,4E,56,2B,DB,AC,3C,0D,74,1634
  824. 310 DATA 0A,3C,20,74,06,E8,1E,00,43,EB,F1,3B,CB,75,11,5E,1519
  825. 320 DATA B0,FF,F3,A6,74,0C,EB,08,90,B4,09,BA,74,01,CD,21,2085
  826. 330 DATA B0,00,B4,4C,CD,21,3C,61,72,09,3C,7A,77,05,24,5F,1387
  827. 340 DATA 88,44,FF,C3,53,79,6E,74,61,78,20,65,72,72,6F,72,1887
  828. 350 DATA 0D,0A,24,00,00,00,00,00,00,00,00,00,00,00,00,00,59
  829.  
  830.  
  831. COMPARE.ASM:
  832.  
  833. compare    segment
  834. ;
  835. ;program to compare two strings
  836. ;case of letters will be ignored in the comparison
  837. ;for use in batch files for comparing strings
  838. ;
  839. ;syntax:  compare string1 string2
  840. ;
  841. ;errorlevel 255 = same string
  842. ;errorlevel 0   = not same string or syntax error
  843. ;
  844. main    proc    far
  845.     assume    cs:compare,ds:compare,es:compare,ss:compare
  846.     org    100h
  847. doscall    equ    21h
  848. prnt_msg equ    09h
  849. exit    equ    4ch
  850.  
  851. start:
  852.     mov    si,81h
  853.     cld
  854.  
  855. start_first_string:
  856.     lodsb
  857.     cmp    al,' '
  858.     je    start_first_string
  859.     cmp    al,0dh
  860.     je    error
  861.     dec    si
  862.     push    si
  863.     pop    di
  864.     sub    cx,cx
  865.  
  866. get_first_string:
  867.     lodsb
  868.     cmp    al,'='
  869.     je    equal_sign
  870.     cmp    al,' '
  871.     je    white_space
  872.     cmp    al,0dh
  873.     je    error
  874.     call    uppercase
  875.     inc    cx
  876.     jmp    get_first_string
  877.  
  878. white_space:
  879.     lodsb
  880.     cmp    al,' '
  881.     je    white_space
  882.     cmp    al,'='
  883.     jne    error
  884.  
  885. equal_sign:
  886.     lodsb
  887.     cmp    al,'='
  888.     jne    error
  889.  
  890. start_second_string:
  891.     lodsb
  892.     cmp    al,' '
  893.     je    start_second_string
  894.     dec    si
  895.     push    si
  896.     sub    bx,bx
  897.  
  898. get_second_string:
  899.     lodsb
  900.     cmp    al,0dh
  901.     je    end_second_string
  902.     cmp    al,' '
  903.     je    end_second_string
  904.     call    uppercase
  905.     inc    bx
  906.     jmp    get_second_string
  907.  
  908. end_second_string:
  909.     cmp    cx,bx
  910.     jne    no_match
  911.     pop    si
  912.     mov    al,255
  913.     repe    cmpsb
  914.     jz    end
  915.     jmp    no_match
  916.  
  917. error:    mov    ah,prnt_msg
  918.     mov    dx,offset synt_msg
  919.     int    doscall
  920.  
  921. no_match:
  922.     mov    al,0
  923.  
  924. end:    mov    ah,exit
  925.     int    doscall
  926.  
  927. main    endp
  928.  
  929. uppercase  proc    near
  930.     cmp    al,'a'
  931.     jb    is_upper
  932.     cmp    al,'z'
  933.     ja    is_upper
  934.     and    al,5fh
  935.     mov    [si-1],al
  936.  
  937. is_upper:
  938.     ret
  939. uppercase  endp
  940.  
  941. synt_msg  db   'Syntax error',0dh,0ah,'$'
  942.  
  943. compare  ends
  944.      end    start
  945.  
  946. -----------------------------------------------------------------
  947.                       Batch File Parameters
  948.          (PC Magazine Vol 5 No 19 Nov 11, 1986 PC Tutor)
  949.  
  950.      If you try to prevent the omission of an important batch file
  951. parameter by using an IF command within a batch file, such as in the
  952. line:
  953.  
  954. IF %1==GOTO ERROR
  955.  
  956. you get a "Syntax Error" from DOS.
  957.      There is a way to check for teh case of a null batch file
  958. variable.  Just put some other character on both sides of the double
  959. equal sign, such as a slash:
  960.  
  961. IF /%1==/ GOTO ERROR
  962.      One of the best ways to learn about batch file tricks is by
  963. exploring the installation programs that software manufacturers often
  964. ship with their products.
  965.  
  966. -----------------------------------------------------------------
  967.                         Pruning the XTREE
  968.         (PC Magazine Vol 5 No 20 Nov 25, 1986 Power User)
  969.  
  970.      XTREE is the hard disk organizer of choice, but its chief
  971. shortcoming is the mandatory read of the entire directory structure.
  972. This problem can be overcome by using the DOS 3.1 SUBST command,
  973. however.  SUBST lets you substitute a drive letter for a path
  974. specification, and the drive letter is acceptable to XTREE.  Invoke
  975. XTREE from a batch file called XTRE.BAT:
  976.  
  977. ECHO OFF
  978. IF P%1==P GOTO FULL
  979.     SUBST D: /D > NUL
  980.     SUBST D:=%1
  981.     XTREE D:
  982.     GOTO END
  983. :FULL
  984.     XTREE
  985. :END
  986.  
  987. The first SUBST turns off any previous SUBSTitutes.  The second assigns
  988. the drive letter D to a pathname specified when invoking the batch
  989. file.  For example, to examine the subdirectory \DOS\UTIL, enter:
  990.  
  991. XTRE \DOS\UTIL
  992.  
  993. Or, to work with the current default directory:
  994.  
  995. XTRE
  996.  
  997. In either case, once in XTREE, you can change back to a full directory
  998. display by logging on to the actual drive.
  999.      Notice that the file begins checking to see if you included a
  1000. pathname.  If not, it jumps to FULL, and XTREE wakes up reading the
  1001. entire directory structure.
  1002.      Editor's Note:  This is one of the more inventive applications
  1003. for SUBST.  Be forewarned, however, that although you may use any
  1004. drive letter (A through Z) as the substitute "drive," DOS normally
  1005. assumes that the last drive is E:.  If A: through E: are already taken
  1006. up by real drives plus a RAMdisk, you'll have to add a new line to
  1007. your CONFIG.SYS file.  The line reads:
  1008.  
  1009. LASTDRIVE = x
  1010.  
  1011. where x is any letter, A through Z.  The value of x becomes the
  1012. highest driver letter that DOS will recognize.
  1013.  
  1014. -----------------------------------------------------------------
  1015.                       Menu Making Made Easy
  1016.        (PC Magazine Vol 5 No 20 Nov 25, 1986 User-to-User)
  1017.  
  1018.      Using the ECHO command to provide prompts or a menu in a batch
  1019. file is handy if the text is short.  But try to display several lines
  1020. or a long menu, and ECHO can be frustratingly slow.  This is even more
  1021. irritating in batch files that routinely loop back and redisplay such
  1022. menus.
  1023.      The solution is to write a short .COM file that uses function 9
  1024. of interrupt 21.  The only read drawback is that this technique won't
  1025. let you display a $, since DOS uses this hex character 24 to mark the
  1026. end of the output string.  To create a MENU.COM file, get into DEBUG
  1027. and type in the script shown below, substituting your own text for the
  1028. dummy "Menu Selection 1" and "Menu Selection 2".
  1029.      To have MENU.COM display more than just two lines, precede each
  1030. line with "DB'" and follow each with the line:
  1031.  
  1032. DB 0D 0A
  1033.  
  1034. However, make sure the very last line of text (and only that line)
  1035. contains an extra hex 24, which is the $ that tells DOS your text is
  1036. done:
  1037.  
  1038. DB 0D 0A 24
  1039.  
  1040. When you've finished entering text and have typed the 24, hit the Enter
  1041. key twice.  They you tell DEBUG how long the file is by typing RCX and
  1042. entering the length of the file in hex.  You can figure out the length
  1043. by subtracting hex 100 from the hex number directly above the RCX.  In
  1044. the example below, this number is 12E, so 12E - 100 = 2E.  Once you're
  1045. done, get into DOS and type MENU to display the text you've entered.
  1046.  
  1047. A>DEBUG
  1048. -N MENU.COM
  1049. -A 100
  1050. XXXX:0100 MOV DX,0109
  1051. XXXX:0103 MOV AH,09
  1052. XXXX:0105 INT 21
  1053. XXXX:0107 INT 20
  1054. XXXX:0109 db 'Menu Selection 1
  1055. XXXX:0119 db 0D 0A
  1056. XXXX:011B db 'Menu Selection 2
  1057. XXXX:012B db 0D 0A 24
  1058. XXXX:012E
  1059. RCX
  1060. CX 0000
  1061. :2E
  1062. -W
  1063. Writing 002E bytes
  1064. -Q
  1065.  
  1066.      Editor's Note:  MENUMAKR.BAS automates the process.  It isn't
  1067. fancy, but it will center lines if you want, and it handles all the
  1068. file creation details for you.  Since it always names the output file
  1069. MENU.COM, if you use MENUMAKR more than once, be sure to remove any
  1070. existing MENU.COM programs you may have created previously.
  1071.  
  1072. 100 'MENUMAKR.BAS
  1073. 110 CLS:DEF FNST$(Z)=MID$(STR$(Z),2)
  1074. 120 DIM A$(24):A=1:TOTAL=0
  1075. 130 PRINT "Enter your line of text #";FNST$(A);":"
  1076. 140 LINE INPUT A$(A)
  1077. 150 IF LEN(A$(A))>79 THEN A$(A)=LEFT$(A$(A),80):GOTO 220
  1078. 160 PRINT "Want it centered (Y/N)?"
  1079. 170 I$=INKEY$:IF I$="" THEN 170
  1080. 180 IF INSTR("YyNn",I$)=0 THEN BEEP:GOTO 170
  1081. 190 IF INSTR("YyNn",I$)>2 THEN 220
  1082. 200 A$(A)=STRING$(40-INT(LEN(A$(A))/2),32)+A$(A)
  1083. 210 PRINT STRING$(2,30);A$(A);CHR$(31)
  1084. 220 A$(A)=A$(A)+CHR$(13)+CHR$(10)
  1085. 230 IF A=24 THEN 290 ELSE A=A+1
  1086. 240 PRINT CHR$(30);"Add any more text (Y/N)?"
  1087. 250 I$=INKEY$:IF I$="" THEN 250
  1088. 260 IF INSTR("YyNn",I$)=0 THEN BEEP:GOTO 250
  1089. 270 IF INSTR("YyNn",I$)>2 THEN 290
  1090. 280 PRINT CHR$(30);:GOTO 130
  1091. 290 OPEN "MENU.COM" FOR OUTPUT AS #1
  1092. 300 FOR B=1 TO 9:READ C:PRINT #1,CHR$(C);:NEXT
  1093. 310 FOR B=1 TO A-1:PRINT #1,A$(B);:NEXT
  1094. 320 PRINT #1,CHR$(36):CLOSE:END
  1095. 330 DATA 186,9,1,180,9,205,33,205,32
  1096.  
  1097. -----------------------------------------------------------------
  1098.                           Capital Idea
  1099.        (PC Magazine Vol 5 No 20 Nov 25, 1986 User-to-User)
  1100.  
  1101.      DOS's IF batch-processing subcommand is case sensitive.  This
  1102. means that for each string comparison, you need two tests -- one for
  1103. uppercase and one for lowercase -- such as:
  1104.  
  1105. IF %1==TEST ECHO This is a match.
  1106. IF %1==test ECHO This is a match.
  1107.  
  1108.      Even this redundant test does not guarantee a match if the string
  1109. you enter is a mixture of uppercase and lowercase letters (as in Test
  1110. or TeSt or TEst).  This can easily happen if the string you enter is a
  1111. city or a person's name or an oddly capitalized computer company -- or
  1112. if you lean too long on the Shift key.
  1113.      DOS 2.1 and DOS 3.1 store user-entered replaceable parameters in
  1114. two entirely different places: DOS 2.1 stores them in the critical
  1115. error-handling segment, and DOS 3.1 stores them just below the
  1116. environment.  Because of this, two different programs -- CAPS2.COM and
  1117. CAPS3.COM -- are required to remove the case sensitivity.
  1118.      Use the CAPSx.SCR file that applies to the version of DOS you are
  1119. using and at the DOS prompt enter either:
  1120.  
  1121. DEBUG < CAPS2.SCR
  1122.  
  1123. or
  1124.  
  1125. DEBUG < CAPS3.SCR
  1126.  
  1127.      Then insert CAPSx.COM at the beginning -- or just after ECHO OFF
  1128. and CLS -- of your batch files and delete the duplicate IF string1==
  1129. string2 commands.  For example, a DOS 3.1 batch file called TEST.BAT
  1130. that tested to see whether a user entered "MicroPro" would look like
  1131. this:
  1132.  
  1133. ECHO OFF
  1134. IF %1!==! GOTO OOPS
  1135. ECHO You entered %1
  1136. CAPS3
  1137. ECHO CAPS3.COM turned it into %1
  1138. IF %1==MicroPro ECHO It works
  1139. GOTO END
  1140. :OOPS
  1141. ECHO Enter TEST MicroPro
  1142. :END
  1143.  
  1144. CAPS2.SCR:
  1145.  
  1146. A
  1147. MOV    AX,[14]
  1148. ADD    AX,B2
  1149. MOV    DS,AX
  1150. MOV    SI,A
  1151. CMP    BYTE PTR [SI],0
  1152. JZ    120
  1153. CMP    BYTE PTR [SI],61
  1154. JB    11D
  1155. CMP    BYTE PTR [SI],7A
  1156. JA    11D
  1157. AND    BYTE PTR [SI],5F
  1158. INC    SI
  1159. JMP    10B
  1160. INT    20
  1161.  
  1162. RCX
  1163. 22
  1164. N CAPS2.COM
  1165. W
  1166. Q
  1167.  
  1168.  
  1169. CAPS3.SCR:
  1170.  
  1171. A
  1172. MOV    AX,[2C]
  1173. SUB    AX,C
  1174. MOV    DS,AX
  1175. MOV    BX,A
  1176. ADD    BX,10
  1177. MOV    SI,BX
  1178. CMP    BYTE PTR [SI],3A
  1179. JNZ    10B
  1180. INC    SI
  1181. CMP    BYTE PTR [SI],5C
  1182. JNZ    10B
  1183. CLD
  1184. LODSB
  1185. CMP    AL,0
  1186. JNZ    11C
  1187. CMP    BYTE PTR [SI],0
  1188. JZ    136
  1189. CMP    BYTE PTR [SI],61
  1190. JB    133
  1191. CMP     BYTE PTR [SI],7A
  1192. JA    133
  1193. AND    BYTE PTR [SI],5F
  1194. INC    SI
  1195. JMP    121
  1196. INT    20
  1197.  
  1198. RCX
  1199. 38
  1200. N CAPS3.COM
  1201. W
  1202. Q
  1203.  
  1204. -----------------------------------------------------------------
  1205.                       Blank Lines with ECHO
  1206.              (PC World November 1986 Star-Dot-Star)
  1207.  
  1208.      The ECHO command behaves differently with DOS 3.1 than it does
  1209. with DOS 2.1.  Under DOS 2.1, an ECHO command followed by several
  1210. space characters would put a blank line on the screen.  DOS 3.1,
  1211. however, ignores spaces and responds by displaying the current ECHO
  1212. status.
  1213.      A simple way to get the better of DOS and echo a blank line is
  1214. to use the ECHO command followed by a space and ASCII character 255.
  1215. To create this character, hold down the Alt key and press the digits
  1216. 255 on the numeric keypad, then release the Alt key.  Although you
  1217. cannot see the difference between ASCII 255 and a space, DOS will not
  1218. consider the line blank and will display a blank line as intended.
  1219.      Some word processors cannot accept the Alt-255 character.  Thus,
  1220. you may have to use the DOS EDLIN program to put the character into
  1221. your batch files.
  1222.  
  1223. -----------------------------------------------------------------
  1224.                     Spacing Out a Batch File
  1225.             (PC World November 1986 The Help Screen)
  1226.  
  1227.      A user inadvertently inserted a space in a batch file -- he
  1228. accidentally placed a space between the second period and the first
  1229. percent sign in the line:
  1230.  
  1231. IF NOT .==.%1 GOTO %1
  1232.  
  1233. rendering the line ineffective.  His solution was to place the first
  1234. occurrent of the replaceable DOS parameter %1 to the left of the first
  1235. period and the double equal signs.  The line worked, even with spaces
  1236. between the %1 and the period.
  1237.      Another line in the batch file, IF %1.==. GOTO HELP, also had a
  1238. replaceable DOS parameter to the left of the double equal signs.
  1239. Although this line will function correctly, it raises an interesting
  1240. point about the placement of DOS's replaceable parameters. The location
  1241. of the replaceable parameter is all-important, and a batch file's
  1242. conditional test for a blank DOS parameter should use:
  1243.  
  1244. if x==%1x command
  1245.  
  1246. rather than:
  1247.  
  1248. if %1x==x command
  1249.  
  1250. because if the string to the right of the == matches the first
  1251. character of the left string but the left string is longer, DOS will
  1252. execute command incorrectly.  You can demonstrate the bug by creating
  1253. two different batch files, A.BAT and B.BAT, and then typing the line:
  1254.  
  1255. IF NOT CONCEPT==CONC A B
  1256.  
  1257. and pressing Enter.  Because CONCEPT is not equivalent to CONC, DOS
  1258. should perform A.  Instead, it selects B.  Although DOS 3.0 and later
  1259. versions don't exhibit this bug, play it safe and always use the
  1260. proper syntax.  And watch those spaces.
  1261.  
  1262. -----------------------------------------------------------------
  1263.                      Subdirectory Navigators
  1264.        (PC Magazine Vol 5 No 21 Dec 9, 1986 User-to-User)
  1265.  
  1266.      VAX mainframes offer several predefined symbols that greatly
  1267. simplify movement through a hierarchical directory structure:  UP,
  1268. DOWN, OVER, and HOME.  These pseudo-commands aren't significantly
  1269. faster than VAX/VMS's SET DEFAULT command, but they are much more
  1270. logically oriented.
  1271.      Four batch files called UP.BAT, DOWN.BAT, OVER.BAT, and HOME.BAT
  1272. can be stored on a RAMdisk and used as if they were actual DOS
  1273. commands.  To go to the parent directory (the one up above the present
  1274. directory), just type UP and hit Enter.  To go to a subdirectory called
  1275. DOS (located down below the present directory), just type DOWN DOS.
  1276. Use OVER to move from the present directory to one having the same
  1277. parent (move over to a directory on the same level).  HOME will return
  1278. you to the root directory.  This is UP.BAT:
  1279.  
  1280. ECHO OFF
  1281. CD..
  1282. CD
  1283.  
  1284. (The CD command lacking an argument simply displays the current
  1285. directory.)  This is DOWN.BAT:
  1286.  
  1287. ECHO OFF
  1288. IF "%1" == "" GOTO NODRSPEC
  1289. CD %1
  1290. CD
  1291. GOTO END
  1292. :NODRSPEC
  1293. ECHO Move down to where?
  1294. :END
  1295.  
  1296. This is OVER.BAT:
  1297.  
  1298. ECHO OFF
  1299. IF "%1" == "" GOTO NODRSPEC
  1300. CD..\%1
  1301. CD
  1302. GOTO END
  1303. :NODRSPEC
  1304. ECHO Move over to where?
  1305. :END
  1306.  
  1307. And this is HOME.BAT:
  1308.  
  1309. ECHO OFF
  1310. CD\
  1311. CD
  1312.  
  1313. When using DOWN.BAT or OVER.BAT, be sure to enter the name of the
  1314. subdirectory where you want to end up.  If you don't specify one, the
  1315. batch file will ask you where you want to go.  (VAX symbol commands at
  1316. work are not nearly so polie; they respond with a ver sarcastic
  1317. "Really, to where?" prompt.)
  1318.      If you are using a RAMdisk, you should copy these files to it.
  1319. If you are not using a RAMdisk, be sure to place the batch files on a
  1320. directory specified by the PATH command in your AUTOEXEC.BAT file.
  1321.  
  1322. -----------------------------------------------------------------
  1323.                 Printer Controls From Batch Files
  1324.         (PC Magazine Vol 5 No 22 Dec 23, 1986 Power User)
  1325.  
  1326.     A word processor can put an IBM Proprinter into near-letter-quality
  1327. mode and leave it there when you exit to DOS.  This can be annoying if
  1328. you then wish to print out some files in draft quality mode.  To reset
  1329. the printer to draft mode, you could add the following line to your
  1330. word processor batch file (immediately after the line calling up the
  1331. word processor):
  1332.  
  1333. TYPE DRAFT.ASC > LPT1:
  1334.  
  1335.      The file DRAFT.ASC contains the following line:
  1336.  
  1337. <ESC>I0
  1338.  
  1339. This escape code is the command to tell the printer to go to draft
  1340. mode.  The <Esc> must be created by a text editor that lets you embed
  1341. control characters in text.  With WordStar or SideKick, for example,
  1342. you would type Ctrl-P <Esc>.  In WordStar, this will show on-screen
  1343. as ^[.  If you type the file to the screen in DOS, the escape code
  1344. will not show at all.
  1345.      With this line added to your batch file, if the printer is off
  1346. when you exit the program, DOS will respond with a "Write fault error"
  1347. and the standard "Abort, Retry, or Ignore" option.  You can then choose
  1348. the abort option or turn the printer on and choose retry instead.
  1349.      One simple extension of this method is to create a series of such
  1350. batch files for different modes (NLQ, condensed, draft).  Then you can
  1351. conveniently switch between modes when printing ASCII files from DOS.
  1352.      Editor's Note:  To take this one step further, you can create
  1353. batch files that will set the printer mode and start printing with a
  1354. single command.  For example, if NLQ.BAT reads:
  1355.  
  1356. TYPE NLQ.ASC > LPT1:
  1357. TYPE %1 > LPT1:
  1358.  
  1359. and NLQ.ASC contains the escape sequence for NLQ mode for your printer,
  1360. then you can set the printer and start printing with the simple command
  1361.  
  1362. NLQ filename
  1363.  
  1364.      To avoid surprises, you might want to choose a "standard" setting
  1365. for the printer and add the appropriate command for that setting at the
  1366. end of each batch file.
  1367.  
  1368. -----------------------------------------------------------------
  1369.                     BASIC Batch Enhancements
  1370.        (PC Magazine Vol 5 No 22 Dec 23, 1986 User-to-User)
  1371.  
  1372.      This system creates a batch file that can access all of the
  1373. subdirectories on your disk.  The DIRSTART.BAT file searches the disk
  1374. and writes a list of the subdirectory names into a file called
  1375. DIRS.DAT.  It then runs the DIRS.BAS program, which processes the
  1376. contents of DIRS.DAT and creates the DIRS.BAT batch file.  DIRS.BAT
  1377. will contain each of your subdirectory names, preceded by two
  1378. replaceable parameters, and will run commands across your entire disk,
  1379. such as:
  1380.  
  1381. DIRS DIR /W
  1382.  
  1383. A similar program, DIRS2.BAS, works like DIRS.BAS except that it places
  1384. the replaceable parameters in different places (the second goes after
  1385. the subdirectory name), which allows wildcard directory searches and
  1386. operations such as:
  1387.  
  1388. DIRS2 DIR *.COM
  1389.  
  1390. If you try DIRS2.BAS, be sure to change the last line in the
  1391. DIRSTART.BAT batch file that runs it, from BASICA DIRS to BASICA DIRS2.
  1392.      The following are some illustrations of this technique:
  1393.  
  1394. DIRS DSORT N
  1395.  
  1396. uses one of the programs in The Norton Utilities to sort all
  1397. subdirectories by filename,
  1398.  
  1399. DIRS2 DIR *.DOC
  1400.  
  1401. displays all of your .DOC filenames,
  1402.  
  1403. DIRS2 DEL *.BAK
  1404.  
  1405. deletes all of the .BAK files in all your subdirectories, and -- try
  1406. this with caution --
  1407.  
  1408. DIRS2 DEL *.*
  1409.  
  1410. erases all files but leaves your subdirectories intact.
  1411.  
  1412.  
  1413. DIRSTART.BAT:
  1414. echo off
  1415. echo Processing disk ....
  1416. chkdsk/v | find "Directory" > DIRS.DAT
  1417. basica dirs     rem Change to "basica dirs2" for DIRS2.BAS
  1418.  
  1419.  
  1420. 100 'DIRS.BAS
  1421. 110 DIM A$(256):DIM B$(256)
  1422. 120 OPEN "DIRS.DAT" FOR INPUT AS #1
  1423. 130 OPEN "DIRS.BAT" FOR OUTPUT AS #2
  1424. 140 PRINT #2,"ECHO OFF"
  1425. 150 LINE INPUT #1,A$
  1426. 160 B$=MID$(A$,11,40)
  1427. 170 PRINT #2,"%1";" ";"%2";" ";B$
  1428. 180 IF EOF(1) GOTO 190 ELSE 150
  1429. 190 CLOSE:SYSTEM
  1430.  
  1431.  
  1432. 100 'DIRS2.BAS
  1433. 110 DIM A$(256):DIM B$(256)
  1434. 120 OPEN "DIRS.DAT" FOR INPUT AS #1
  1435. 130 OPEN "DIRS2.BAT" FOR OUTPUT AS #2
  1436. 140 PRINT #2,"ECHO OFF"
  1437. 150 LINE INPUT #1,A$
  1438. 160 B$=MID$(A$,11,40)
  1439. 170 PRINT #2,"%1";" ";B$;
  1440. 180 IF LEN(B$)>3 THEN 200
  1441. 190 PRINT #2,"%2":GOTO 210
  1442. 200 PRINT #2,"\";"%2"
  1443. 210 IF EOF(1) GOTO 220 ELSE 150
  1444. 220 CLOSE:SYSTEM
  1445.  
  1446.      Editor's Note:  Once you've used CHKDSK /V | FIND "Dir" > DIRS.DAT
  1447. to create the list of subdirectories, rather than write a BASIC program
  1448. you can use the search-and-replace mechanism of your word processor to
  1449. create batch files such as the two mentioned here.  This technique
  1450. shows the real brute-force power of DOS, especially when it comes to
  1451. replaceable parameters.  Remember to have BASIC handy when you run
  1452. these, or have it in a subdirectory that's included in your PATH.  You
  1453. can also use SWEEP.COM (PC Mag Vol 4 No 23) to do many of these jobs
  1454. faster and more elegantly.
  1455.  
  1456. -----------------------------------------------------------------
  1457.                         Don't Tread On Me
  1458.        (PC Magazine Vol 5 No 22 Dec 23, 1986 User-to-User)
  1459.  
  1460.      Software vendors often include an AUTOEXEC.BAT file on their
  1461. distribution disks or provide an installation program that creates one.
  1462. By merely copying the distribution disk (using COPY *.*) to your hard
  1463. disk root directory or simply installing the program, you might wipe
  1464. out your own carefully designed pre-existing AUTOEXEC.BAT file.
  1465. Although installing each software package in its own directory can
  1466. reduce this risk, the method is not foolproof.  To eliminate the risk
  1467. entirely, never use AUTOEXEC.BAT as the real name for the sequence of
  1468. commands you want to execute on start-up.
  1469.      Since the AUTOEXEC.BAT file is no different from any other file
  1470. except for its name, and since any .BAT file can execute another .BAT
  1471. file, you AUTOEXEC.BAT file can contain one simple, easy-to-remember
  1472. command:  STARTUP.BAT.  STARTUP.BAT contains all the commands that
  1473. would normally be in AUTOEXEC.BAT.
  1474.      You never have to worry then about blowing away your start-up
  1475. routines by overlooking an AUTOEXEC.BAT file on a distribution disk,
  1476. or an installation program that creates its own.  Furthermore, the
  1477. name STARTUP.BAT itself is an obvious clue as to what AUTOEXEC.BAT
  1478. should contain if you ever need to re-create it.
  1479.      Editor's Note:  Some programs routinely corrupt both AUTOEXEC.BAT
  1480. and CONFIG.SYS.  It was once easy to spot this, since programs would
  1481. install themselves through long batch files that you could read and
  1482. change with a word processor.  But many programs now use .COM and .EXE
  1483. files to do the installation.
  1484.      Another elegant protection solution is to change COMMAND.COM so
  1485. that it will look for a batch file with a name other than AUTOEXEC.BAT.
  1486. In fact, the first file COMMAND.COM tries to execute doesn't even have
  1487. to end in .BAT.  To try this, make a copy of COMMAND.COM and type:
  1488.  
  1489. DEBUG COMMAND.COM
  1490.  
  1491. Find out how long your version of COMMAND.COM is by typing RCX and
  1492. hitting the Enter key twice.  DEBUG will respond by printing the
  1493. letters CX and then the file's length in hex.  For instance, in DOS
  1494. 3.1, you'd see:
  1495.  
  1496. CX 5AAA
  1497.  
  1498. Then search for AUTOEXEC.BAT by typing in:
  1499.  
  1500. S 100 5AAA "AUTO"
  1501.  
  1502. (substituting the actual length for other versions of COMMAND.COM that
  1503. DEBUG prints after the CX).  DEBUG will then print the address of the
  1504. beginning of the name AUTOEXEC.BAT, which in DOS 3.1 would look like:
  1505.  
  1506. 5506:130F
  1507.  
  1508. (Ignore the four hex numbers on the left; they'll vary from system to
  1509. system, and they don't matter here.)
  1510.      AUTOEXEC.BAT is 12 characters long (11 for the filename and 1 for
  1511. the period before the extension), so you have to remember to pad out
  1512. the extra spaces if the new name you replace it with has fewer than 12
  1513. characters.  To replace AUTOEXEC.BAT with STARTUP, under DOS 3.1 type:
  1514.  
  1515. E 130F "STARTUP     "
  1516.  
  1517. To check your work, type:
  1518.  
  1519. D 130F
  1520.  
  1521. and make sure you've written over all traces of AUTOEXEC.BAT.
  1522.      To save the modified COMMAND.COM, type:
  1523.  
  1524. W
  1525.  
  1526. followed by:
  1527.  
  1528. Q
  1529.  
  1530. to end the DEBUG session.
  1531.      Then rename your old AUTOEXEC.BAT file to STARTUP and reboot.
  1532. However, if you don't like changing COMMAND.COM, the next best
  1533. safeguard is to keep a subdirectory called \BAKUP that contains your
  1534. AUTOEXEC.BAT, COMMAND.COM, and CONFIG.SYS files.  If new programs
  1535. obliterate your old main startup files, you can always type:
  1536.  
  1537. COPY \BAKUP\*.* \
  1538.  
  1539. -----------------------------------------------------------------
  1540.                       Aborting AUTOEXEC.BAT
  1541.        (PC Magazine Vol 5 No 22 Dec 23, 1986 User-to-User)
  1542.  
  1543.      Sometimes you don't want to run your hard disk AUTOEXEC.BAT.  A
  1544. combination of resident programs loaded by your AUTOEXEC.BAT might
  1545. cause your machine to hang.  Or you might not want to run a product
  1546. your AUTOEXEC.BAT installs (for example, you might not want to bring
  1547. up the PC Network before doing backups).
  1548.      In either case, one solution is to boot off a floppy disk in
  1549. drive A:.  Or you can continuously press Ctrl-Break while your machine
  1550. is booting, hoping your AUTOEXEC.BAT will abort before the critical
  1551. instructions occur.  Either solution is fine if you run into the
  1552. problem only once in a while, but neither is ideal.
  1553.      A far better solution is to use a small program called KBFLAG.COM
  1554. to monitor your keyboard as you boot up and send a code to your
  1555. AUTOEXEC.BAT file that an IF ERRORLEVEL instruction can trap.  To
  1556. create the KBFLAG.COM program, type in the following KBFLAG.SCR script,
  1557. using the DOS COPY CON command or any pure-ASCII word processor:
  1558.  
  1559. N KBFLAG.COM
  1560. A
  1561. MOV AX,40
  1562. MOV DS,AX
  1563. MOV AL,[17]
  1564. MOV AH,4C
  1565. INT 21
  1566.  
  1567. RCX
  1568. C
  1569. W
  1570. Q
  1571.  
  1572. Be sure to leave a blank line above RCX and hit the Enter key at the
  1573. end of each line, especially the last one.  Once you install this
  1574. program, you can press one single key while your machine is booting
  1575. to avoid running your AUTOEXEC.BAT.
  1576.      Then, add these two lines at the very beginning of your
  1577. AUTOEXEC.BAT:
  1578.  
  1579. KBFLAG
  1580. IF ERRORLEVEL 1 GOTO
  1581.  
  1582. Note: The second statement is syntactically incorrect.  When ERRORLEVEL
  1583. is nonzero, you will get a message about a missing label (since the
  1584. GOTO does not specify a label).  Ignore the error message.  The
  1585. important thing is that the remainder of the .BAT file will not be
  1586. executed.
  1587.      KBFLAG simply sets the DOS ERRORLEVEL to the value of the KBFLAG
  1588. in the ROM BIOS area.  You can use different keys to trigger KBFLAG.
  1589. These keys, and the codes read by IF ERRORLEVEL, are:
  1590.  
  1591.   1 = Right Shift
  1592.   2 = Left Shift
  1593.   4 = Ctrl key
  1594.   8 = Alt-Shift
  1595.  16 = ScrollLock
  1596.  32 = NumLock
  1597.  64 = CapsLock
  1598. 128 = Ins
  1599.  
  1600. For example, you can avoid running AUTOEXEC.BAT if you press and hold
  1601. the Shift key while your machine boots, or if you simply press NumLock
  1602. while your CONFIG.SYS is running.  The latter technique is preferable
  1603. in some situations.  (Long CONFIG.SYS files can run for over a minute
  1604. -- you wouldn't want to have to hold the Shift key down that long.)
  1605.      You can add the above key values together.  For example, if you
  1606. wanted the trigger to be the Right and Left Shift keys plus the Ins
  1607. key (toggled on) you would use an ERRORLEVEL trap of 131 (1+2+128=131).
  1608.      You could also make your batch file test for several ERRORLEVELs
  1609. or act differently when different keys are pressed.  For example,
  1610. CapsLock could mean abort the AUTOEXEC.BAT, while NumLock could do
  1611. everything but load a couple of resident programs.  Of course, KBFLAG
  1612. can be used in any .BAT file, not just your AUTOEXEC.BAT.
  1613.      Editor's Note:  Stopping the execution of a batch file by forcing
  1614. a syntax error works, but there's a much simpler way to avoid running
  1615. the batch file.  Make the first two lines of your AUTOEXEC.BAT:
  1616.  
  1617. KBFLAG
  1618. IF ERRORLEVEL 128 GOTO :END
  1619.  
  1620. and then add a line at the very end of the batch file:
  1621.  
  1622. :END
  1623.  
  1624. Then you can avoid running your AUTOEXEC.BAT file by toggling the Ins
  1625. key when you boot up.  KBFLAG will send a 128 to the IF ERRORLEVEL
  1626. trap, which will branch to the :END label.  This is far more elegant
  1627. than pounding on the keyboard, which can generate 301 bootup errors
  1628. and force you to hit the F1 key and then restart the whole operation.
  1629. Using the Ins toggle means you can branch out of the program with one
  1630. simple key press, or start normally by keeping your fingers off the
  1631. keyboard.
  1632.  
  1633. -----------------------------------------------------------------
  1634.                        AUTOEXEC Autopilot
  1635.              (PC World December 1986 Star-Dot-Star)
  1636.  
  1637.      A number of different computers, all configured differently, are
  1638. used in an office.  Some have two floppy drives, some have one, some
  1639. have a hard disk, some do not.  This AUTOEXEC.BAT file determines which
  1640. drive letter refers to the RAM disk, so that the start-up process
  1641. operates properly on every machine.
  1642.      The techniques relies on the fact that when the system is turned
  1643. on, there are no files in the RAM disk.  The first IF EXIST command
  1644. tests for the presence of files on drive C:.  If there are none, drive
  1645. C: is the RAM disk.  If a file is present, drive C: must be a hard
  1646. disk, so the batch file branches to :isDhard and checks whether drive
  1647. D: has any files.  If there is no file, drive D: is the RAM disk; if
  1648. there is, drive E: is the RAM disk.
  1649.      Once the drive letter of the RAM disk is determined, the batch
  1650. file uses the SET command to assign that letter to a variable that can
  1651. be used by other commands within the batch file.  The following command
  1652. uses that variable as the drive letter and copies a second batch file
  1653. to the RAM disk.  The second batch file contains the remainder of the
  1654. start-up commands and executes from the RAM disk.  When the first batch
  1655. file transfers execution to the second, it passes the RAM disk drive
  1656. letter on as a command line parameter for use by other commands within
  1657. the second file.
  1658.  
  1659. echo off
  1660. cls
  1661. if exist c:*.* goto isDhard
  1662. echo No fixed disk present
  1663. set ramdisk=C:
  1664. goto :more
  1665. :isDhard
  1666. if exist d:*.* goto D
  1667. echo Fixed disk is drive C:
  1668. set ramdisk=D:
  1669. goto more
  1670. :D
  1671. echo Fixed disk is drive D:
  1672. set ramdisk=E:
  1673. :more
  1674. echo RAM disk is drive %ramdisk%
  1675. copy a:autobat2.bat %ramdisk% >nul
  1676. %ramdisk%
  1677. autobat2 %ramdisk%
  1678.  
  1679.      Editor's Note:  If you often use different PC's, and one has more
  1680. than two hard disks or a hard disk that is divided into more than two
  1681. volumes, you must notify AUTOBAT.BAT to also check those drives for
  1682. files.
  1683.  
  1684.